package com.study.ApplicationEvent2.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import com.study.ApplicationEvent2.UserBean;
import com.study.ApplicationEvent2.UserRegisterEvent;

@Service
public class UserService {

	@Autowired
	ApplicationContext applicationContext;
	
	public void register(UserBean user){
		//其他业务逻辑
		
		//发布UserRegisterEvent 事件
		//事件发布是由ApplicationContext对象管控的，我们发布事件前需要注入ApplicationContext对象调用publishEvent方法完成事件发布。
		applicationContext.publishEvent(new UserRegisterEvent(this,user));
	}
}
